
#ifndef COMMON_TASK_PROCESSOR_H_
#define COMMON_TASK_PROCESSOR_H_

#include "./fiber-pool.h"
#include "./queue.h"

namespace fasmio { namespace common {

template <typename HostClass, typename TaskClass>
class TaskProcessor : protected FiberPool
{
    typedef Queue<TaskClass> queue_t;
    typedef HostClass host_t;
    typedef void (HostClass::*task_handler)(TaskClass* task);

public:
    explicit TaskProcessor(ILogger* logger, const char* fiber_name);
    virtual ~TaskProcessor();

public:
    bool Start(unsigned int fiber_count, queue_t &queue, HostClass* host, task_handler handler);
    void Stop();

protected:
    virtual void Worker();

private:
    queue_t *queue_;
    host_t *host_;
    task_handler handler_;
};

}}  // namespace fasmio::common

#include "./task-processor-aux.h"
#endif  // COMMON_TASK_PROCESSOR_H_

